﻿using System;
using System.Collections;
using System.IO;

public enum SortOption
{
    FileName,
    Extension,
    CreationTime
}

public class SortFile : IComparer
{
    SortOption mso;
    public SortFile(SortOption so)
    {
        mso = so;
    }

    int IComparer.Compare(object a, object b)
    {
        if (a is FileSystemInfo)
        {
            FileSystemInfo fa = (FileSystemInfo)a;
            FileSystemInfo fb = (FileSystemInfo)b;
            switch (mso)
            {
                case SortOption.FileName:
                    return String.Compare(fa.Name, fb.Name, true);
                case SortOption.Extension:
                    return String.Compare(Path.GetExtension(fa.Name), Path.GetExtension(fb.Name), true);
                case SortOption.CreationTime:
                    return DateTime.Compare(fa.CreationTime, fb.CreationTime);
                default:
                    break; ;
            }
        }
        return 0;
    }

}